package bag.servlet;

import bag.domain.Product;
import bag.service.CartService;
import bag.service.impl.CartServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.xml.ws.Service;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 冷丶 on 2017/10/24.
 */
@WebServlet(name = "AddShopServlet",urlPatterns = "/addShopServlet")
public class AddShopServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Product product = new Product();
        try {
            BeanUtils.populate(product,request.getParameterMap());
            CartService service = new CartServiceImpl();
            int count = service.insert(product);
            response.sendRedirect("/work/shopListServlet");
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

//        request.getRequestDispatcher("addshop.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }


}
